package com.game.beans;

import com.game.GameWindow;
import com.game.utils.GameState;
import com.game.utils.GameUtils;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

public class HeroBean extends GameBean{
    public HeroBean() {
        super();
    }

    public HeroBean(BufferedImage img, int x, int y, double speed) {
        super(img, x, y, speed);
    }

    public HeroBean(BufferedImage img, int x, int y, int width, int height, double speed, GameWindow frame) {
        super(img, x, y, width, height, speed, frame);
        this.frame.addMouseMotionListener(new MouseAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                HeroBean.super.setX(e.getX() - width / 2);
                HeroBean.super.setY(e.getY() - height / 2);
            }
        });
    }

    @Override
    public void paintSelf(Graphics graphics) {
        super.paintSelf(graphics);
        for (EnemyBean enemyBean: GameUtils.enemyBeans
             ) {
            if (this.getRectangle().intersects(enemyBean.getRectangle())){

                GameWindow.state = GameState.GAMEOVER;
            }
        }
    }

    @Override
    public Rectangle getRectangle() {
        return super.getRectangle();
    }
}
